"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const components_1 = require("@tarojs/components");
const taro_1 = require("@tarojs/taro");
require("./login.scss");
const Login = () => {
    const addUser = (res) => {
        try {
            taro_1.default.cloud.callFunction({
                name: "logins",
                data: {
                    $url: "addUser",
                    nickName: res.userInfo.nickName,
                    avatar: res.userInfo.avatarUrl
                }
            });
        }
        catch (err) {
            console.log(err);
        }
    };
    const login = () => {
        taro_1.default.getUserProfile({
            desc: "获取用户头像，姓名",
            success: res => {
                // console.log(res);
                taro_1.default.setStorageSync("userInfo", res.userInfo);
                addUser(res);
                taro_1.default.navigateBack();
            },
            fail: () => {
                taro_1.default.showToast({ title: "用户登录失败", icon: "error" });
            }
        });
    };
    return (<components_1.View className="index">
      <components_1.View></components_1.View>
      <components_1.View className="btn" onClick={login}>
        微信授权一键登录
      </components_1.View>
    </components_1.View>);
};
exports.default = Login;
//# sourceMappingURL=login.jsx.map